<?php
/**
 * Words Rule
 * Validates that a string contains word characters.
 * This means alpha-numeric plus underscore. You can optionally choose
 * not to allow whitespace with the 'whitespace' param.
 * 
 * @package Q-Validate
 * @subpackage Rules
 * @author Luke Visinoni <luke.visinoni@gmail.com>
 * @copyright (c) 2010 Luke Visinoni <luke.visinoni@gmail.com>
 * @todo Unit tests
 * @version $Id: Words.php 37 2010-12-23 02:38:44Z luke.visinoni $
 */
class Q_Rule_Words extends Q_Rule_Abstract {

    /**
     * The parameters that were passed to this rule
     */
    protected $_params = array(
        'whitespace' => true,
    );
    
    public function isValid($value) {
    
        if ($this->getParam('whitespace')) {
            $pattern = '/^[\w\s]+$/D';
        } else {
            $pattern = '/^\w+$/D';
        }
        return $this->_validatePattern($pattern, $value);
    
    }

}
